import {
	defineStore
} from 'pinia'
import http from '@/utils/http.js'

import {
	useUserStore
} from './user'
const userStore = useUserStore()

// order
export const useOrderStore = defineStore('order', {
	// state
	state: () => ({
		showPayment: false, //是否显示支付弹窗
		payData: null, //支付数据
		payType: 'new', // 支付类型 new 新订单 ， old 老订单 offline，线下
		total: 0 //总价
	}),



	// action
	actions: {
		closePayment() { //关闭支付弹窗
			this.showPayment = false
			this.payData = null
		},
		openPayment(data) { //打开支付弹窗
			this.showPayment = true
			this.payData = data.payData
			this.payType = data.payType
			this.total = data.total
		},

		openPayment(data) {
			return new Promise((resolve, reject) => {
				// dispatch('user/syncUserInfo', {}, {
				// 	root: true
				// })

				userStore.syncUserInfo().then(res => { //获取到最新的余额
					// commit('openPayment', data)
					this.openPayment(data)
				})
			})
		}
	}
})